import numpy as np


class Point:  # 点类
    def __init__(self, length, width, height):
        self.x = length  # x
        self.y = width  # y
        self.z = height  # z


class Node:
    def __init__(self, point, length, width, height, obstacle):  # 结点类
        self.point = point
        self.Q = np.zeros(26)  # 该状态26个动作的Q值表
        self.r = 0  # 该结点奖励
        self.length = length
        self.width = width
        self.height = height
        self.obstacle = obstacle  # 地图信息
        self.fathernode = None  # 父结点

    def isOut(self):  # 判断该节点是否在地图外
        if self.point.x >= self.length or self.point.x < 0:
            self.r = -100
            return 1
        elif self.point.y >= self.width or self.point.y < 0:
            self.r = -100
            return 1
        elif self.point.z >= self.height or self.point.z < 0:
            self.r = -100
            return 1
        else:
            return 0

    def isObstacle(self):  # 判断该节点是否是障碍物区域
        for i in self.obstacle:
            if i[0] <= self.point.x <= i[0] + 1 and i[1] <= self.point.y <= i[1] + 1 and i[2] >= self.point.z:
                self.r = -100
                return 1
            else:
                return 0

    def isEnd(self,endpoint):  # 判断节点是否是终点
        if self.point.x == endpoint[0] and self.point.y == endpoint[1] and self.point.z == endpoint[2]:
            #print("it's over!")
            return 1
        else:
            return 0